package com.xdpdp.smile.consumer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 原始版服务调用演示
 *
 * @author Herman
 * @description :
 **/
@Service
public class ConsumerServiceImpl implements ConsumerServiceAPI {

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public String sayHello(String message) {
        // 准备工作
//        String hostname = "localhost";
//        int port = 7101;
//        String uri = "/provider/sayhello?message="+message;

        // GET Register
        //ServiceInstance choose = eurekaClient.choose("backend-show-provider");
//        String hostname = choose.getHost();
//        int port = choose.getPort();


        // http://localhost:7101/provider/sayhello?message=hello

        String uri = "/provider/sayhello?message=" + message;
        String url = "http://backend-show-provider"+ uri;

        // invoker provider test
        String result = restTemplate.getForObject(url, String.class);

        return result;
    }

}
